home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 831 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: engnews1.Eng.Sun.COM!usenet
  2. From: johnb@pivotal-dm.ccmail.compuserve.com (John Bain)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Referencing pointers after delete
  5. Date: 23 Mar 1996 17:09:03 GMT
  6. Organization: Pivotal Technologies Ltd.
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <315274d1.8486150@dub-news-svc-3.compuserve.com>
  9. References: <4is05t$ceo@engnews1.Eng.Sun.COM>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. X-Nntp-Posting-Host: hd62-202.compuserve.com
  12. X-Newsreader: Forte Agent .99d/32.182
  13. Content-Length: 1280
  14.  
  15. "joe (j.) halpin" <jhalpin@bnr.ca> wrote:
  16.  
  17. >In 3.7.3.2.4 the January working paper says:
  18. >
  19. >4 A deallocation function can free the storage referenced by the pointer
  20. >  given  as  its  argument and renders the pointer invalid.  The storage
  21. >  can be made available for further allocation.  An invalid pointer con-
  22. >  tains an unusable value:  it cannot even be used in an expression.
  23.  
  24. I interpret this as meaning the _value_ of the pointer cannot be used in
  25. an expression.
  26.  
  27. >
  28. >This sounds as though, in the following:
  29. >
  30. >char *pc = new char[128];
  31. >delete pc;
  32.     ^^^^
  33. delete[] pc;
  34.  
  35. >pc = 0;
  36. >
  37. >it makes the final assignment (an expression) invalid.
  38.  
  39. The value of the pointer is not used in the expression, so it's OK.
  40.  
  41. >In fact, it sounds like it also rules out things like 'if(pc == 0)
  42. >...' after the above fragment.
  43.  
  44. After the final assignment, the pointer's value is no longer invalid, so
  45. it can be used (though obviously not dereferenced while NULL).
  46.  
  47. By my interpretation, (pc == 0) would, however, be invalid after the
  48. delete but before the assignment of 0.
  49.  
  50. Cheers,
  51.  
  52. John
  53. -----------------------------------------------------------------
  54. John Bain                  
  55. johnb@pivotal-dm.ccmail.compuserve.com 
  56. -----------------------------------------------------------------
  57.  
  58.  
  59.  
  60. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  61. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  62. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  63. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  64. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  65.